

//
//  DetailHeroViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DetailHeroViewController.h"
#import "HeroView.h"
#import "HeroModel.h"
#import "UIImageView+WebCache.h"
#import "AFNetworking.h"
#import "HeroSkinViewController.h"
#import "HeroTalentViewController.h"
#import "UIImageView+WebCache.h"
#import <AVFoundation/AVFoundation.h>
#import "DetailHeroTableViewCell.h"
#import "HeroEquipmentModel.h"
#import "HeroDataViewController.h"
#import "GMDCircleLoader.h"
@interface DetailHeroViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UITableView *heroTableView;
@property(nonatomic, retain)NSMutableArray *soundArr;
@property(nonatomic, retain)NSMutableArray *groupArr;
@property(nonatomic, retain)NSMutableArray *equipArr;
@property(nonatomic, retain)NSMutableDictionary *Herodic;
@property(nonatomic, retain)UISegmentedControl *selectSeg;
@property(nonatomic, retain)NSMutableArray *transformArr;
@property(nonatomic, retain)UIScrollView *heroView;
@property(nonatomic, retain)HeroView *skillB;
@property(nonatomic, retain)SVSegmentedControl *sound;
@property(nonatomic, retain)UISegmentedControl *skillItem;// 技能栏
@property(nonatomic, retain)UILabel  *nameLabel;
@property(nonatomic, retain)UILabel *cooldownLabel;// 冷却时间
@property(nonatomic, retain)UILabel *costLabel; // 消耗
@property(nonatomic, retain)UILabel *descriptionLabel;// 描述
@property(nonatomic, retain)UILabel *effectLabel; // 效果
@property(nonatomic, retain)AVPlayer *player; // 音乐播放器
@property(nonatomic, retain)AVPlayerItem *playItem;// 音乐播放项目


@end

@implementation DetailHeroViewController
- (void)dealloc
{   [_enName release];
    [_cnName release];
    [_title1 release];
    [_location release];
    [_price release];
    [_rating release];
    [_heroTableView release];
    [_soundArr release];
    [_groupArr release];
    [_equipArr release];
    [_Herodic release];
    [_selectSeg release];
    [_transformArr release];
    [_heroView release];
    [_skillB release];
    [_sound release];
    [_skillItem release];
    [_nameLabel release];
    [_cooldownLabel release];
    [_costLabel release];
    [_descriptionLabel release];
    [_effectLabel release];
    [_player release];
    [_playItem release];
    [super dealloc];



}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.soundArr = [NSMutableArray array];
        self.groupArr = [NSMutableArray array];
        self.transformArr = [NSMutableArray array];
        self.Herodic = [NSMutableDictionary dictionary];
        self.equipArr = [NSMutableArray array];
    }

    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // 解析数据开始
    [self heroDetailData];
    [self createView];
    // Do any additional setup after loading the view.


}
// 铺设视图
- (void)createView
{

    HeroView *baseView = [[HeroView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT * 1.14992503748)];
    baseView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:baseView];
    // 铺设自定义View
    self.heroView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    self.heroView.contentSize = CGSizeMake(VIEWWIDTH, VIEWHEIGHT * 1.224887556);
    [baseView addSubview:self.heroView];
    self.heroView.backgroundColor = [UIColor whiteColor];
    [_heroView  release];


    // 铺设tableView
    self.heroTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, VIEWHEIGHT/4.168, VIEWWIDTH, 390 * VIEWHEIGHT / 667.0 ) style:UITableViewStylePlain];
    [self.heroView addSubview:self.heroTableView];
    [_heroTableView release];
    self.heroTableView.dataSource = self;
    self.heroTableView.delegate = self;


#pragma mark 英雄详情部分
    // 添加英雄头像
    UIImageView *heroImagerView = [[UIImageView alloc] initWithFrame:CGRectMake(VIEWWIDTH/75, VIEWWIDTH/75, VIEWWIDTH/4.6875, VIEWWIDTH/4.6875)];
    NSString *imageStr = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/champions/%@_120x120.jpg",self.enName];
    NSURL *url = [NSURL URLWithString:imageStr];
    [heroImagerView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
    [self.heroView addSubview:heroImagerView];
    [heroImagerView release];


    // 英雄名称 价格 定位  难度 UILabel
    // 名称
    UILabel *heroNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(VIEWWIDTH/4.1666, VIEWHEIGHT * 0.00749625187, VIEWWIDTH * 0.53333333, VIEWHEIGHT/33.35)];
    NSString *name = [NSString stringWithFormat:@"%@ %@",self.title1,self.self.cnName];
    heroNameLabel.text = name;

    [self.heroView addSubview:heroNameLabel];
    [heroNameLabel release];

    // 价格
    UILabel *heroPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(VIEWWIDTH/4.1666, 0.0449775112 * VIEWHEIGHT, VIEWWIDTH * 0.533333333, 0.02248875562219 * VIEWHEIGHT)];
    NSString *goldPrice = [self.price substringToIndex:4];
    NSString *realPrice = [self.price substringFromIndex:5];
    NSString *price = [NSString stringWithFormat:@"金币:%@ 点券:%@",goldPrice,realPrice];
    heroPriceLabel.text = price;
    heroPriceLabel.font = [UIFont systemFontOfSize:12];
    [self.heroView addSubview:heroPriceLabel];
    [heroPriceLabel release];

    // 定位
    UILabel *heroLocationLabel = [[UILabel alloc] initWithFrame:CGRectMake(VIEWWIDTH/4.1666, 0.074963518 * VIEWHEIGHT, 0.4 * VIEWWIDTH, VIEWHEIGHT * 0.0224887556)];
    heroLocationLabel.text = self.location;
    heroLocationLabel.font  = [UIFont systemFontOfSize:12];
    [self.heroView addSubview:heroLocationLabel];
    [heroLocationLabel release];
    // 操作信息
    UILabel *heroControlLabel = [[UILabel alloc] initWithFrame:CGRectMake(VIEWWIDTH/4.1666, VIEWHEIGHT * 0.1049475, VIEWWIDTH * 0.53333333, VIEWHEIGHT * 0.022488755)];
    NSArray *temp = [self.rating componentsSeparatedByString:@","];
    NSString *attack = temp[0];
    NSString *mage = temp[1];
    NSString *defence = temp[2];
    NSString *difficulty = temp[3];
    NSString *operation = [NSString stringWithFormat:@"物理:%@ 法术:%@ 防御:%@ 难度:%@",attack,mage,defence,difficulty];
    heroControlLabel.text = operation;
    heroControlLabel.font = [UIFont systemFontOfSize:12];

    [self.heroView addSubview:heroControlLabel];
    [heroControlLabel release];

    // 英雄数据
    UIButton *dataButton = [UIButton buttonWithType:UIButtonTypeSystem];
    dataButton.frame = CGRectMake(VIEWWIDTH * 0.77333333, 0.0149925 * VIEWHEIGHT, VIEWWIDTH * 0.18666666, VIEWHEIGHT * 0.029985);
    dataButton.backgroundColor = [UIColor cyanColor];
    dataButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [dataButton setTitle:@"英雄数据" forState:UIControlStateNormal];
    [dataButton addTarget:self action:@selector(dataAction:) forControlEvents:UIControlEventTouchUpInside];
    dataButton.layer.cornerRadius = 5;
    [self.heroView addSubview:dataButton];



    // 皮肤按钮
    UIButton *skinButton = [UIButton buttonWithType:UIButtonTypeSystem];
    skinButton.frame = CGRectMake(0.773333333 * VIEWWIDTH, 0.0524737 * VIEWHEIGHT, VIEWWIDTH * 0.18666666, 0.029985 * VIEWHEIGHT);
    skinButton.backgroundColor = [UIColor cyanColor];
    skinButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [skinButton setTitle:@"英雄皮肤" forState:UIControlStateNormal];
    [skinButton addTarget:self action:@selector(skinAction:) forControlEvents:UIControlEventTouchUpInside];
    skinButton.layer.cornerRadius = 5;
    [self.heroView addSubview:skinButton];

    // 天赋符文

    UIButton *talentButton = [UIButton buttonWithType:UIButtonTypeSystem];
    talentButton.frame = CGRectMake(0.773333333 * VIEWWIDTH,0.089955 * VIEWHEIGHT, VIEWWIDTH * 0.18666666, 0.029985 * VIEWHEIGHT);
    talentButton.backgroundColor = [UIColor cyanColor];
    talentButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [talentButton setTitle:@"天赋符文" forState:UIControlStateNormal];
    [talentButton addTarget:self action:@selector(talentAction:) forControlEvents:UIControlEventTouchUpInside];
    talentButton.layer.cornerRadius = 5;
    [self.heroView addSubview:talentButton];


    // 分类显示seg
    self.selectSeg = [[UISegmentedControl alloc] initWithItems:@[@"技能",@"介绍",@"出装",@"配音"]];
    self.selectSeg.frame = CGRectMake(0.013333333 * VIEWWIDTH, 0.1349325337 * VIEWHEIGHT, VIEWWIDTH - 0.026666667 * VIEWWIDTH, 0.047976 * VIEWHEIGHT);
    self.selectSeg.tintColor = [UIColor brownColor];
    [self.selectSeg addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventValueChanged];
    [self.heroView addSubview:self.selectSeg];

    [_selectSeg release];


    // 技能栏
    self.skillItem = [[UISegmentedControl alloc] initWithItems:@[@"",@"",@"",@"",@""]];
    self.skillItem.frame = CGRectMake(0.013333333 * VIEWWIDTH, 0.1814409295  * VIEWHEIGHT, 0.586666667 * VIEWWIDTH, 0.0674662667 * VIEWHEIGHT);
    UILabel *qSkill = [[UILabel alloc] initWithFrame:CGRectMake(0.192 * VIEWWIDTH, 0.044977511 * VIEWHEIGHT, 0.04 * VIEWWIDTH, 0.022488756 * VIEWHEIGHT)];

    qSkill.alpha = 0.8;
    qSkill.text = @"Q";
    qSkill.textColor = [UIColor whiteColor];
    [self.skillItem addSubview:qSkill];
    qSkill.tag = 8080;
    [qSkill release];



    UILabel *wSkill = [[UILabel alloc] initWithFrame:CGRectMake(0.309333333 * VIEWWIDTH, 0.044977511 * VIEWHEIGHT, 0.04 * VIEWWIDTH, 0.022488756 * VIEWHEIGHT)];

    wSkill.alpha = 0.8;
    wSkill.text = @"W";
    wSkill.textColor = [UIColor whiteColor];
    [self.skillItem addSubview:wSkill];
    wSkill.tag = 8081;
    [wSkill release];
    UILabel *eSkill = [[UILabel alloc] initWithFrame:CGRectMake(0.42666667 * VIEWWIDTH, 0.044977511 * VIEWHEIGHT, 0.04 * VIEWWIDTH, 0.022488756 * VIEWHEIGHT)];

    eSkill.alpha = 0.8;
    eSkill.text = @"E";
    eSkill.tag = 8082;
    eSkill.textColor = [UIColor whiteColor];
    [self.skillItem addSubview:eSkill];
    [eSkill release];
    UILabel *rSkill = [[UILabel alloc] initWithFrame:CGRectMake(0.544 * VIEWWIDTH, 0.044977511 * VIEWHEIGHT, 0.04 * VIEWWIDTH, 0.022488756 * VIEWHEIGHT)];

    rSkill.alpha = 0.8;
    rSkill.text = @"R";
    rSkill.tag = 8083;
    rSkill.textColor = [UIColor whiteColor];
    [self.skillItem addSubview:rSkill];
    [rSkill release];

    self.skillItem.tag = 1000;
    self.skillItem.hidden = YES;

    [self.heroView addSubview:self.skillItem];

    [_skillItem release];

    // 给segment 添加背景图片
    NSMutableArray *arr =[self heroSkillImage:self.enName];

    //技能图片
    for (NSInteger i = 0; i <= 4; i++)
    {

        [self.skillItem setImage:[[UIImage imageWithData:arr[i]] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] forSegmentAtIndex:i];
    }



    // 技能图片点击事件
    [self.skillItem addTarget:self action:@selector(skillAction:) forControlEvents:UIControlEventValueChanged];



    self.sound = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"英雄配音",@"其他配音",nil]];
    self.sound.frame = CGRectMake(0.26666667 * VIEWWIDTH, 0.19490255 * VIEWHEIGHT, 0.48 * VIEWWIDTH, 0.047976 * VIEWHEIGHT);
    self.sound.font = [UIFont systemFontOfSize:17];
    self.sound.thumb.tintColor = [UIColor colorWithRed:0 green:0.5 blue:0.1 alpha:1];
    // 是否只能滑动来更改位置
    //        sound.mustSlideToChange = YES;
    [self.heroView addSubview:self.sound];
    self.sound.hidden = YES;
    [self.sound addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];

}

#pragma mark 铺设技能栏视图
- (void)createSkillView
{
    self.skillB = [[HeroView alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.30144404 * VIEWHEIGHT,VIEWWIDTH - 0.026666667 * VIEWWIDTH, VIEWHEIGHT - 0.306859 * VIEWHEIGHT)];

    [self.heroView addSubview:self.skillB];

    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.00902527 * VIEWHEIGHT, 0.8 * VIEWWIDTH, 0.03610108 * VIEWHEIGHT)];
    self.nameLabel.font = [UIFont systemFontOfSize:16];
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.lineBreakMode = NSLineBreakByCharWrapping;


    self.costLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.0541516 * VIEWHEIGHT, 0.8 * VIEWWIDTH, 0.03610108 * VIEWHEIGHT)];
    self.costLabel.font = [UIFont systemFontOfSize:16];
    self.costLabel.numberOfLines = 0;
    self.costLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.costLabel.backgroundColor = [UIColor whiteColor];

    self.cooldownLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.0992779 * VIEWHEIGHT, 0.8 * VIEWWIDTH, 0.03610108 * VIEWHEIGHT)];
    self.cooldownLabel.font = [UIFont systemFontOfSize:16];
    self.cooldownLabel.numberOfLines = 0;
    self.cooldownLabel.lineBreakMode = NSLineBreakByCharWrapping;


    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.144404 *VIEWHEIGHT, VIEWWIDTH - 0.0533333 * VIEWWIDTH, 0.234657 * VIEWHEIGHT)];
    self.descriptionLabel.numberOfLines = 0;
    self.descriptionLabel.textAlignment = NSTextAlignmentJustified;
    self.descriptionLabel.font = [UIFont systemFontOfSize:17];
    self.descriptionLabel.lineBreakMode = NSLineBreakByCharWrapping;

    self.effectLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.01333333 * VIEWWIDTH, 0.37906 * VIEWHEIGHT, VIEWWIDTH - 20, 0.541516 * VIEWHEIGHT)];
    self.effectLabel.numberOfLines = 0;
    self.effectLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.effectLabel.textAlignment = NSTextAlignmentJustified;
    self.effectLabel.font = [UIFont systemFontOfSize:17];

    [self.skillB addSubview:self.nameLabel];
    [self.skillB addSubview:self.costLabel];
    [self.skillB addSubview:self.cooldownLabel];
    [self.skillB addSubview:self.descriptionLabel];
    [self.skillB addSubview:self.effectLabel];

    [_skillB release];

    [_nameLabel release];
    [_cooldownLabel release];
    [_costLabel release];
    [_descriptionLabel release];
    [_effectLabel release];




}

// 英雄技能图片解析方法
- (NSMutableArray *)heroSkillImage:(NSString *)enName
{

    NSString *skill_B = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_B_64x64.png",enName];
    NSString *skill_Q = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_Q_64x64.png",enName];
    NSString *skill_W = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_W_64x64.png",enName];
    NSString *skill_E = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_E_64x64.png",enName];
    NSString *skill_R = [NSString stringWithFormat:@"http://img.lolbox.duowan.com/abilities/%@_R_64x64.png",enName];
    NSData *tempB = [NSData dataWithContentsOfURL:[NSURL URLWithString:skill_B]];
    NSData *tempQ = [NSData dataWithContentsOfURL:[NSURL URLWithString:skill_Q]];
    NSData *tempW = [NSData dataWithContentsOfURL:[NSURL URLWithString:skill_W]];
    NSData *tempE = [NSData dataWithContentsOfURL:[NSURL URLWithString:skill_E]];
    NSData *tempR = [NSData dataWithContentsOfURL:[NSURL URLWithString:skill_R]];

   NSMutableArray *arr = [NSMutableArray arrayWithObjects:tempB,tempQ,tempW,tempE,tempR, nil];



    return arr;



}

#pragma mark 技能图片点击事件
- (void)skillAction:(id)sender
{

        NSInteger index = self.skillItem.selectedSegmentIndex;
        NSString *temp = self.enName;
        if (index == 0)
        {
            self.skillItem.highlighted = YES;
        NSString *skillB = [NSString stringWithFormat:@"%@_B",temp];
            NSString *name = [NSString stringWithFormat:@"名称:%@",self.Herodic[skillB][@"name"]];
        self.nameLabel.text = name ;


            if ([self.Herodic[skillB][@"cost"]isEqualToString:@""]) {
                self.costLabel.text = @"消耗:无";
            }else{
                NSString *cost = [NSString stringWithFormat:@"消耗:%@",self.Herodic[skillB][@"cost"]];
                self.costLabel.text = cost;
            }


            if ([self.Herodic[temp][@"cooldown"]isEqualToString:@""]) {
                self.cooldownLabel.text = @"冷却时间:无";
            }else{

               NSString *cooldown = [NSString stringWithFormat:@"冷却时间:%@",self.Herodic[skillB][@"cooldown"]];
                self.cooldownLabel.text = cooldown;
            }




            NSString *description = [NSString stringWithFormat:@"描述:\n%@",self.Herodic[skillB][@"description"]];
        self.descriptionLabel.text = description;
            NSString *effect = [NSString stringWithFormat:@"效果:\n%@",self.Herodic[skillB][@"effect"]];
        self.effectLabel.text = effect;





        }else if (index == 1){
            NSString *skillQ = [NSString stringWithFormat:@"%@_Q",temp];
            NSString *name = [NSString stringWithFormat:@"名称:%@",self.Herodic[skillQ][@"name"                    ]];
            self.nameLabel.text = name ;


            if ([self.Herodic[skillQ][@"cost"]isEqualToString:@""]) {
                self.costLabel.text = @"消耗:无";
            }else{
                NSString *cost = [NSString stringWithFormat:@"消耗:%@",self.Herodic[skillQ][@"cost"]];
                self.costLabel.text = cost;
            }


            if ([self.Herodic[temp][@"cooldown"]isEqualToString:@""]) {
                self.cooldownLabel.text = @"冷却时间:无";
            }else{

                NSString *cooldown = [NSString stringWithFormat:@"冷却时间:%@",self.Herodic[skillQ][@"cooldown"]];
                self.cooldownLabel.text = cooldown;
            }




            NSString *description = [NSString stringWithFormat:@"描述:\n%@",self.Herodic[skillQ][@"description"]];
            self.descriptionLabel.text = description;
            NSString *effect = [NSString stringWithFormat:@"效果:\n%@",self.Herodic[skillQ][@"effect"]];
            self.effectLabel.text = effect;

        }else if (index == 2){
            NSString *skillW = [NSString stringWithFormat:@"%@_W",temp];
            NSString *name = [NSString stringWithFormat:@"名称:%@",self.Herodic[skillW][@"name"]];
            self.nameLabel.text = name ;


            if ([self.Herodic[skillW][@"cost"]isEqualToString:@""]) {
                self.costLabel.text = @"消耗:无";
            }else{
                NSString *cost = [NSString stringWithFormat:@"消耗:%@",self.Herodic[skillW][@"cost"]];
                self.costLabel.text = cost;
            }


            if ([self.Herodic[temp][@"cooldown"]isEqualToString:@""]) {
                self.cooldownLabel.text = @"冷却时间:无";
            }else{

                NSString *cooldown = [NSString stringWithFormat:@"冷却时间:%@",self.Herodic[skillW][@"cooldown"]];
                self.cooldownLabel.text = cooldown;
            }




            NSString *description = [NSString stringWithFormat:@"描述:\n%@",self.Herodic[skillW][@"description"]];
            self.descriptionLabel.text = description;
            NSString *effect = [NSString stringWithFormat:@"效果:\n%@",self.Herodic[skillW][@"effect"]];
            self.effectLabel.text = effect;


        }else if (index == 3)
        {
            NSString *skillE = [NSString stringWithFormat:@"%@_E",temp];
            NSString *name = [NSString stringWithFormat:@"名称:%@",self.Herodic[skillE][@"name"]];
            self.nameLabel.text = name ;


            if ([self.Herodic[skillE][@"cost"]isEqualToString:@""]) {
                self.costLabel.text = @"消耗:无";
            }else{
                NSString *cost = [NSString stringWithFormat:@"消耗:%@",self.Herodic[skillE][@"cost"]];
                self.costLabel.text = cost;
            }


            if ([self.Herodic[temp][@"cooldown"]isEqualToString:@""]) {
                self.cooldownLabel.text = @"冷却时间:无";
            }else{

                NSString *cooldown = [NSString stringWithFormat:@"冷却时间:%@",self.Herodic[skillE][@"cooldown"]];
                self.cooldownLabel.text = cooldown;
            }



            NSString *description = [NSString stringWithFormat:@"描述:\n%@",self.Herodic[skillE][@"description"]];
            self.descriptionLabel.text = description;
            NSString *effect = [NSString stringWithFormat:@"效果:\n%@",self.Herodic[skillE][@"effect"]];
            self.effectLabel.text = effect;






        }else if (index == 4){


            NSString *skillR = [NSString stringWithFormat:@"%@_R",temp];
            NSString *name = [NSString stringWithFormat:@"名称:%@",self.Herodic[skillR][@"name"]];
            self.nameLabel.text = name ;


            if ([self.Herodic[skillR][@"cost"]isEqualToString:@""]) {
                self.costLabel.text = @"消耗:无";
            }else{
                NSString *cost = [NSString stringWithFormat:@"消耗:%@",self.Herodic[skillR][@"cost"]];
                self.costLabel.text = cost;
            }


            if ([self.Herodic[temp][@"cooldown"]isEqualToString:@""]) {
                self.cooldownLabel.text = @"冷却时间:无";
            }else{

                NSString *cooldown = [NSString stringWithFormat:@"冷却时间:%@",self.Herodic[skillR][@"cooldown"]];
                self.cooldownLabel.text = cooldown;
            }




            NSString *description = [NSString stringWithFormat:@"描述:\n%@",self.Herodic[skillR][@"description"]];
            self.descriptionLabel.text = description;
            NSString *effect = [NSString stringWithFormat:@"效果:\n%@",self.Herodic[skillR][@"effect"]];
            self.effectLabel.text = effect;


        }
    









}
// tableView 必须实现的两个方法
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.selectSeg.selectedSegmentIndex == 1) {
        return 1;
    }else{

    return self.transformArr.count;
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  // 点击介绍下标
{    if (self.selectSeg.selectedSegmentIndex == 1){
         static NSString *reuse1 = @"reuse1";
    DetailHeroTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse1];
    if (!cell) {
        cell = [[[DetailHeroTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse1] autorelease];
    }
    cell.selectionStyle = NO;
    cell.textLabel.text = [self.transformArr[indexPath.section] lastObject];
    cell.textLabel.font = [UIFont systemFontOfSize:16];

    cell.textLabel.numberOfLines = 0;
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;



    return cell;
}  // 介绍
else if (self.selectSeg.selectedSegmentIndex == 2)
{


        static NSString *reuse2 = @"reuse2";
        DetailHeroTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse2];
        if (!cell) {
            cell = [[[DetailHeroTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse2] autorelease];
        }
        HeroEquipmentModel *model = self.transformArr[indexPath.row] ;
    cell.selectionStyle = NO;
    cell.titleLabel.text = model.title;
    cell.serverLabel.text = model.server;
    cell.authorLabel.text = model.author;
    cell.combatLabel.text = model.combat;
    cell.combatView.image = [UIImage imageNamed:@"iconfont-dacumojian"];
    // 装备图片转换
    NSString *temp = model.end_cz;
    NSArray *arr = [temp componentsSeparatedByString:@","];
    if (arr.count == 6) {

        NSURL *url1= [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[0]]];
        NSURL *url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[1]]];
        NSURL *url3 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[2]]];
        NSURL *url4 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[3]]];
        NSURL *url5 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[4]]];
        NSURL *url6 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[5]]];
        [cell.equipView1 sd_setImageWithURL:url1];
        [cell.equipView2 sd_setImageWithURL:url2];
        [cell.equipView3 sd_setImageWithURL:url3];
        [cell.equipView4 sd_setImageWithURL:url4];
        [cell.equipView5 sd_setImageWithURL:url5];
        [cell.equipView6 sd_setImageWithURL:url6];
    }
    else if(arr.count == 5){


        NSURL *url1= [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[0]]];
        NSURL *url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[1]]];
        NSURL *url3 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[2]]];
        NSURL *url4 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[3]]];
        NSURL *url5 = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.lolbox.duowan.com/zb/%@_64x64.png",arr[4]]];

        [cell.equipView1 sd_setImageWithURL:url1];
        [cell.equipView2 sd_setImageWithURL:url2];
        [cell.equipView3 sd_setImageWithURL:url3];
        [cell.equipView4 sd_setImageWithURL:url4];
        [cell.equipView5 sd_setImageWithURL:url5];



    }



        return cell;





}
    // 点击配音下标
     else if (self.selectSeg.selectedSegmentIndex == 3){
         static NSString *reuse3 = @"reuse3";
         DetailHeroTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse3];
         if (!cell) {
             cell = [[[DetailHeroTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse3] autorelease];
         }
         cell.textLabel.text = self.transformArr[indexPath.row];
    
         
         
         
         return cell;
    }else
    {
        return 0;
    }
}

// section 个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    if (self.selectSeg.selectedSegmentIndex == 1) {
        return self.groupArr.count;
    }else
    {


        return 1;
    }



}

// 标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{   if (self.selectSeg.selectedSegmentIndex == 1){

    return self.groupArr[section];
}
else{
      return 0;
}

}
// 文本自适应
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   if (self.selectSeg.selectedSegmentIndex == 1){
    // 根据对应的文字,求出label显示需要的高度
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16],NSFontAttributeName, nil];
    CGRect rect = [[self.transformArr[indexPath.section] lastObject] boundingRectWithSize:CGSizeMake(320 * VIEWWIDTH / 375, 15000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height + 40;





}else if (self.selectSeg.selectedSegmentIndex == 2){

    return 120;
}

else {


    return 50;
}




}
#pragma mark tableViewCell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   NSInteger index = self.sound.selectedSegmentIndex;
    if (index == 0) {
        NSString* temp = self.transformArr[indexPath.row];
        NSString *sound = [NSString stringWithFormat:@"http://box.dwstatic.com/sounds/%@/%@?&v=86&OSType=iOS8.3&versionName=2.2.1",self.enName,temp];
        NSString *stringEndcoding  = [sound stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:stringEndcoding];
        self.playItem = [[AVPlayerItem alloc] initWithURL:url];
        self.player = [[AVPlayer alloc] initWithPlayerItem:self.playItem];
        [self.player play];
        [_playItem release];
        [_player release];
    }else
    {
        NSString* temp = self.transformArr[indexPath.row];
        NSString *sound = [NSString stringWithFormat:@"http://box.dwstatic.com/sounds/Common/Common_%@?&v=86&OSType=iOS8.3&versionName=2.2.1",temp];
        NSString *stringEndcoding  = [sound stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:stringEndcoding];
        self.playItem = [[AVPlayerItem alloc] initWithURL:url];
        self.player = [[AVPlayer alloc] initWithPlayerItem:self.playItem];
        [self.player play];
        [_playItem release];
        [_player release];







    }








}

#pragma mark 按钮点击事件 数据 皮肤  天赋
- (void)dataAction:(id)sender
{
    HeroDataViewController *data =[[HeroDataViewController alloc] init];
    data.heroDataDic = self.Herodic;
    [self.navigationController pushViewController:data animated:YES];
    [data release];



}

- (void)skinAction:(id)sender
{
    HeroSkinViewController *heroSkin = [[HeroSkinViewController alloc] init];
    heroSkin.heroName = self.enName;
    [self.navigationController pushViewController:heroSkin animated:YES];
    [heroSkin release];



}


- (void)talentAction:(id)sender
{

    HeroTalentViewController *heroTalent = [[HeroTalentViewController alloc] init];
    heroTalent.heroName = self.enName;
    [self.navigationController pushViewController:heroTalent animated:YES];
    [heroTalent release];

    
    
}


#pragma mark 英雄详细数据解析
- (void)heroDetailData
{
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中..." animated:YES];
    // 英雄数据解析
    NSString *temp = [NSString stringWithFormat:@"http://lolbox.duowan.com/phone/apiHeroDetail.php?v=70&OSType=iOS7.1.1&heroName=%@",self.enName];
    AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager];
    [manger GET:temp parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
    {   
        self.Herodic = responseObject;
         [self createSkillView];
        [self.selectSeg setSelectedSegmentIndex:0];
        [self.skillItem setSelectedSegmentIndex:0];
        [self clickAction:self.selectSeg];
        [self skillAction:self.skillItem];
        [self.heroTableView reloadData];
        [GMDCircleLoader hideFromView:self.view animated:YES];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error");
    }];


    // 英雄音乐
    NSString *heroSound = [NSString stringWithFormat:@"http://box.dwstatic.com/apiHeroSound.php?hero=%@&v=70&OSType=iOS7.1.1&versionName=2.2.1",self.enName];

    AFHTTPRequestOperationManager *soundManager = [AFHTTPRequestOperationManager manager];
    [soundManager GET:heroSound parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
           self.soundArr =  responseObject;



    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"我网络请求失败");
    }];

  // 英雄出装
    AFHTTPRequestOperationManager *equitManager = [AFHTTPRequestOperationManager manager];
    NSString *heroEquip = [NSString stringWithFormat:@"http://db.duowan.com/lolcz/img/ku11/api/lolcz.php?limit=7&OSType=iOS7.1.1&v=70&championName=%@",self.enName];
     [equitManager GET:heroEquip parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSMutableArray *temp = responseObject;

         for (NSMutableDictionary *dic in temp) {
             HeroEquipmentModel *model = [[HeroEquipmentModel alloc] init];
             [model setValuesForKeysWithDictionary:dic];
             [self.equipArr addObject:model];
             [model release];
         }


     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

     }];





}

#pragma mark  分类 点击事件
- (void)clickAction:(id)sender
{
    [self.transformArr removeAllObjects];
    NSInteger index = self.selectSeg.selectedSegmentIndex;
    // 判断是否下标为0
    if (index != 0) {
        self.skillItem.hidden = YES;
        self.skillB.hidden = YES;
        self.heroView.contentOffset = CGPointMake(0, 0);
        self.heroView.ScrollEnabled = NO;
    }else
    {
        self.skillItem.hidden = NO;
        self.skillB.hidden = NO;
        self.heroView.ScrollEnabled = YES;
    }
   // 判断下标是否为3
    if (index != 3)
    {
        self.sound.hidden = YES;
       self.heroTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;

      }else
    {
        self.sound.hidden = NO;



    }



    if (index == 0)
    {

        [self.heroTableView reloadData];



    }else if (index == 1)
    {
        NSMutableArray *one = [NSMutableArray arrayWithObject:self.Herodic[@"tips"]];
        NSMutableArray *two = [NSMutableArray arrayWithObject:self.Herodic[@"opponentTips"]];
        NSMutableArray *three = [NSMutableArray arrayWithObject:self.Herodic[@"description"]];
        self.transformArr = [NSMutableArray arrayWithObjects:one,two,three,nil];
         self.groupArr = [NSMutableArray arrayWithObjects:@"使用技巧",@"对抗技巧",@"背景故事",nil];
        [self.heroTableView reloadData];







    }else if (index == 2)
    {

          self.heroTableView.separatorStyle =  UITableViewCellSeparatorStyleSingleLine;
        for (HeroEquipmentModel *model in self.equipArr) {
            [self.transformArr addObject:model];
        }
        [self.heroTableView reloadData];


    }else if (index == 3)
    {
         self.heroTableView.separatorStyle =  UITableViewCellSeparatorStyleSingleLine;

        [self.sound setSelectedSegmentIndex:0 animated:YES];

        [self segmentedControlChangedValue:self.sound];









    }






}
#pragma mark 筛选英雄条件

- (void)segmentedControlChangedValue:(SVSegmentedControl* )segmentedControl
{   [self.transformArr removeAllObjects];
    NSInteger index = segmentedControl.selectedSegmentIndex;

    if (index == 0){
        for (NSString *temp in self.soundArr) {
            [self.transformArr addObject:temp];
        }

        [self.heroTableView reloadData];


    }
    if (index == 1){



        self.transformArr = [NSMutableArray arrayWithObjects:@"一血.mp3",@"双杀.mp3",@"三杀.mp3",@"四杀.mp3",@"五杀.mp3",@"团灭.mp3",@"大杀特杀(三连杀).mp3",@"暴走(四连杀).mp3",@"无人能挡(五连杀).mp3",@"主宰比赛(六连杀).mp3",@"接近神(七连杀).mp3",@"超神(八连杀及以上).mp3",@"终结击杀.mp3",@"欢迎来到英雄联盟.mp3",@"全军出击.mp3",@"敌军还有30秒到达战场.mp3",@"胜利.mp3",@"失败.mp3",@"啦啦啦德玛西亚1.mp3",@"啦啦啦德玛西亚2.mp3",@"啦啦啦德玛西亚3.mp3", nil];


        [self.heroTableView reloadData];


    }







}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
